<%@ page
	import="com.jobsika.server.domain.User"
	import="com.jobsika.jdo.UserUtil"
	import="com.jobsika.jdo.PMF"
	import="javax.jdo.PersistenceManager" %>
<%  PersistenceManager pm = PMF.get().getPersistenceManager();
	String username = request.getParameter("username");
	String identity = request.getParameter("identity");
	String time     = request.getParameter("time");
	String[] friends = request.getParameterValues("friends");
	out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
	out.println("<result>");
	if (username != null && identity != null) {
		if (UserUtil.containsUser(pm, username)) {
			User user = UserUtil.getUser(pm, username);
			if (user != null) {
				user.setIdentity(identity);
				out.println("\t<update>true</update>");
				UserUtil.persistUser(pm, user);
			}
		} else {
			User user = new User();
			user.setEmail(username);
			user.setIdentity(identity);
			UserUtil.persistUser(pm, user);
		}
	}
	if (friends != null) {
		for (String friend : friends) {
			out.println("\t<friend>");
			out.println("\t\t<user>"+friend+"</user>");
			if (UserUtil.containsUser(pm, friend)) {
				User f = UserUtil.getUser(pm, friend);
				if (f.getIdentity() != null) {
					out.println("\t\t<identity>"+f.getIdentity()+"</identity>");
				}
			}
			out.println("\t</friend>");
		}
	}
	out.println("</result>");
%>